package day05;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.Set;

import org.junit.Test;

/**
 * 有下列字符串:
 * 销售:张三;财务:李四;销售:王五;财务:赵六;程序:mike;程序:jerry;美工:jackson;前端:green;前端:nick;程序:钱七;销售:alice
 * 分析上述字符串然后统计每个职位总共多少人?
 * 使用Map保存统计的结果，其中key:职位,value为该职位人数
 * 然后分别输出各职位的名称(keySet),各职位人数(entrySet)
 * @author Bonnie
 *
 */
public class Test05 {
	 @Test
	 public void test() {
		 Scanner console = new Scanner(System.in);
		 System.out.print("请输入字符串：");
		 String str = console.nextLine();
		 String[] info = str.split(";");
		 Map<String, Integer> map = new HashMap<String, Integer>();
		 for (int i = 0; i < info.length; i++) {
			 String[] ss = info[i].split(":");
			 String job = ss[0];
			 String name = ss[1];
			 if (map.containsKey(job)) {
				 map.put(job, map.get(job) + 1);
			 } else {
				 map.put(job, 1);
			 }
		 }
		 Set<String> keySet = map.keySet();
		 for (String key : keySet) {
			 System.out.print(key);
			 System.out.print('\t');
		 }
		 System.out.println();
		 Set<Entry<String, Integer>> entrySet = map.entrySet();
		 for (Entry entry : entrySet) {
			 System.out.print(entry.getValue());
			 System.out.print('\t');
		 }
		 System.out.println();
		 for (Entry entry : entrySet) {
			 System.out.println(entry.getKey() + "=" + entry.getValue());
		 }
		 console.close();
	 }
}
